#pragma once
#include<functional>
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>

// 包装器 + lambda
std::function<void(void)> PrintLog = [](){ std::cout << "我是一个打印日志的任务" << std::endl; };
std::function<void(void)> DownLoad = [](){ std::cout << "我是一个下载的任务" << std::endl; };
std::function<void(void)> UpLoad = [](){ std::cout << "我是一个上传的任务" << std::endl; };

class TaskManager
{
    typedef std::function<void(void)> task_t;
public:
    TaskManager()
    {
        srand(time(nullptr));
    }

    void Register(task_t t)
    {
        _tasks.push_back(t);
    }

    int Code()
    {
        return rand() % _tasks.size();
    }

    void Execute(int code)
    {
        if(code >= 0 && code < _tasks.size())
        {
            _tasks[code]();
        }
    }

private:
    std::vector<task_t> _tasks;
};

